import { ConfigEnv, defineConfig, loadEnv } from 'vite';
import loadConfig from 'postcss-load-config'; // 加载postcss配置
import { pluginsConfig } from './config/plugins';
import { resolve } from 'path';
import { serverConfig } from './config/server';
// https://vite.dev/config/
export default defineConfig(async (configEnv: ConfigEnv) => {
  const postcssConfig = await loadConfig();
  console.log(configEnv, 'configEnv');
  const { mode } = configEnv;
  const isDev = mode === 'development' ? true : false; // 是否是开发环境
  const variable = loadEnv(mode, process.cwd(), '');
  return {
    plugins: pluginsConfig(isDev),
    resolve: {
      alias: {
        '@': resolve(__dirname, 'src'),
      },
    },
    css: {
      postcss: postcssConfig,
    },
    server: serverConfig(variable),
  };
});
